#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int d[maxn];
int v[maxn];
int a[maxn];
int p[maxn];
double zz[maxn];
double zz2[maxn];
set<int>st;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(false);
    int T;
    cin>>T;
    while(T--){
        int n,m,L,V;
        cin>>n>>m>>L>>V;
        bool f1=0,f2=0,f3=0;
        for(int i=1;i<=n;i++){
            cin>>d[i]>>v[i]>>a[i];
            if(a[i]>=0){
                f1=1;
            }
            if(a[i]!=0){
                f2=1;
            }
            if(a[i]<=0){
                f3=1;
            }
        }
        for(int i=1;i<=m;i++){
            cin>>p[i];
        }
        if(f2==0){//a=0
            sort(p+1,p+m+1);
            int cnt1=0;
            for(int i=1;i<=n;i++){
                if(v[i]>V&&d[i]<=p[m]){
                    cnt1++;
                }
            }
            if(cnt1==0) cout<<cnt1<<" "<<m<<endl;
            else cout<<cnt1<<" "<<m-1<<endl;
        }
        else if(f1==0){//a<0
            while(!st.empty()){
                st.erase(st.begin());
            }
            sort(p+1,p+m+1);
            p[m+1]=INT_MAX;
            int cnt2=0;
            for(int i=1;i<=n;i++){
                if(d[i]>p[m]) continue;
                int j=lower_bound(p+1,p+m+1,d[i])-p;
                if(j!=m+1){
                    zz[i]=sqrt((p[j]-d[i])*a[i]*2.0+1.0*v[i]*v[i]);
                    if(zz[i]>1.0*V){
                        cnt2++;
                        double lc=(V*V*1.0-v[i]*v[i]*1.0)/(2.0*a[i]);
                        int k=upper_bound(p+1,p+m+1,d[i]+int(lc))-p-1;
                        st.insert(k);
                    }
                }
            }
            cout<<cnt2<<" "<<m-st.size()<<endl;
        } else {//a>0
            sort(p+1,p+m+1);
            int cnt3=0;
            for(int i=1;i<=n;i++){
                if(d[i]>p[m]) continue;
                zz[i]=sqrt((p[m]-d[i])*2.0*a[i]+v[i]*v[i]);//
                if(zz[i]>1.0*V) cnt3++;
            }
            cout<<cnt3<<" "<<m-1<<endl;
        }
    }//40
    return 0;
}
